version: "3.9"

volumes:
  kafka-volume:
  grafana-volume:
  postgres-volume:

networks:
  monitoring:

services:

  kafka1:
    image: bitnami/kafka:3.6.2
    ports:
    - "9092:9092"
    environment:
    - KAFKA_ENABLE_KRAFT=yes
    - KAFKA_KRAFT_CLUSTER_ID=bdb3_vRdRhC-spk2HZw9iw
    - KAFKA_CFG_PROCESS_ROLES=broker,controller
    - KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER
    - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092,CONTROLLER://:9093
    - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP=CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
    - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://kafka1:9092
    - KAFKA_CFG_NODE_ID=1
    - KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@kafka1:9093
    - ALLOW_PLAINTEXT_LISTENER=yes
    volumes:
    - kafka-volume:/bitnami/kafka
    networks:
    - monitoring

  admin-ui:
    image: provectuslabs/kafka-ui:v0.7.2
    ports:
    - "9080:8080"
    environment:
    - KAFKA_CLUSTERS_0_BOOTSTRAP_SERVERS=kafka1:9092
    - KAFKA_CLUSTERS_0_NAME=kraft
    networks:
    - monitoring

  grafana:
    image: grafana/grafana:10.4.2
    ports:
    - 3000:3000
    networks:
    - monitoring
    volumes:
    - grafana-volume:/var/lib/grafana
    environment:
    - GF_SECURITY_ADMIN_USER=admin
    - GF_SECURITY_ADMIN_PASSWORD=admin12345

  jobmanager:
    image: flink:1.19-java17
    ports:
    - "8081:8081"
    command: jobmanager
    environment:
      FLINK_PROPERTIES: "jobmanager.rpc.address: jobmanager"
    volumes:
    - .:/home
    networks:
    - monitoring

  taskmanager:
    image: flink:1.19-java17
    depends_on:
    - jobmanager
    - kafka1
    command: taskmanager
    environment:
    - flink.verbose_logs=true
    - |
      FLINK_PROPERTIES=
      jobmanager.rpc.address: jobmanager
      taskmanager.numberOfTaskSlots: 8
    volumes:
    - .:/home
    networks:
    - monitoring

  sampler:
    image: unlocker/monitoring-data-sampler:1.0-SNAPSHOT
    depends_on:
    - kafka1
    networks:
    - monitoring
    volumes:
    - type: bind
      source: ./data/events
      target: /opt/data/events
    command:
    - java
    - -Dkafka.bootstrap.servers=kafka1:9092
    - -jar
    - application.jar
    - --tick=PT5M
    - /opt/data/events/events.csv

  postgres:
    image: postgres:14.8-alpine3.18
    environment:
      POSTGRES_DB: "customs"
      POSTGRES_USER: "customs"
      POSTGRES_PASSWORD: "customs"
      PGDATA: "/var/lib/postgresql/data/pgdata"
    volumes:
    - postgres-volume:/var/lib/postgresql/data/pgdata
    - ./data/pginit:/docker-entrypoint-initdb.d
    ports:
    - "5432:5432"
    networks:
    - monitoring

